<?php

/**
 * Class cash 提现管理
 */
Class cashControl extends BaseSellerControl{

    /**
     * 提现管理列表
     */
     public function indexOp(){
         $condition = array();
         if($_GET['state']){
                $condition['state'] = $_GET['state'];
         }else{
                $condition['state'] = 0;
         }
         $condition['class'] = 0;
         $cash = model("predeposit");
         $cash_list = $cash->getCashList($condition);
         foreach($cash_list as $k => $v){
             $member = Model('member')->getMemberInfoByID($v['member_id']);
             $cash_list[$k]['member_name'] = $member['member_name'];
         }
         Tpl::output('class',0);
         Tpl::output('list',$cash_list);
         Tpl::showpage('cash_index');
     }

     /**
      * 提现编辑
      */
    public function editOp(){
        $where['id'] = intval($_GET['id']);
        $model_pd = Model('cash_withdrawal_apply');
        $info = $model_pd->where($where)->find();
        $member = Model('member')->getMemberInfoByID($info['member_id']);
        $info['member_name'] = $member['member_name'];
        Tpl::output('info',$info);
        Tpl::showpage("cash_edit");
    }

    /**
     * 保存编辑
     */
    public function save_editOp(){
        $where['id'] = $_POST['pdc_id'];
        $data['state'] = intval($_POST['status']);
        $data['remarks'] = intval($_POST['remark']);
        $class = $_POST['class'];
        $data['verification_time'] = time();
        $cash = model("predeposit");
        $info = $cash->editCash($data,$where);
        if($info) {
             //冻结款清零
             $condition['member_id'] = $_POST['pdc_member_id'];
             $member_info = Model('member')->getMemberInfoByID($_POST['pdc_member_id']);
             if($_POST['status']==1) {
                 // 审核成功
                 if ($class == 0) {
                     $updata['freeze_predeposit'] = 0;
                 }
                 if ($class == 1) {
                     $updata['store_freeze_brokerage'] = 0;
                 }
                 if ($class == 2) {
                     $updata['freeze_brokerage'] = 0;
                 }
             }else{
                 // 审核失败
                 if ($class == 0) {
                     $updata['available_predeposit'] = $member_info['available_predeposit']+$member_info['freeze_predeposit'];
                     $updata['freeze_predeposit'] = 0;
                 }
                 if ($class == 1) {
                     $updata['av_store_brokerage'] = $member_info['av_store_brokerage']+$member_info['store_freeze_brokerage'];
                     $updata['store_freeze_brokerage'] = 0;
                 }
                 if ($class == 2) {
                     $updata['av_brokerage'] = $member_info['av_brokerage']+$member_info['freeze_brokerage'];
                     $updata['freeze_brokerage'] = 0;
                 }
             }
              $res = Model('member')->editMember($condition,$updata);
              if($res){
                  if($res){
                      showDialog('操作成功！',  urlShop('cash','index'),'succ');
                  }else{
                      showDialog('操作失败！',  urlShop('cash','index'));
                  }
              }
        }else{
            showDialog('操作失败！',  urlShop('cash','index'));
        }
    }
}